<?PHP
class SimpleResultTable
{
	private $html = null;

	public function __construct(){
		
	}
	
	public function getHTML($query){
		$this->html = '';
		$this->html = $this->html.'<fieldset><table><tr><td>Nome</td><td>Label</td></tr>';			
		if ($query != null) {
			while ($row = $query->fetch_row()) {
				$this->html = $this->html.'<tr>';
				$this->html = $this->html.'<td>'.$row[2].'</td>';
				$this->html = $this->html.'<td>'.$row[4].'</td>';
				$this->html = $this->html.'</tr>';
			}
			$query->close();
		}
		$this->html = $this->html.'</table></fieldset>';
		return $this->html;
	}
	
	public function fetch_all_assoc(& $result,$index_keys) {

		$assoc = array();

		while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

		$pointer = & $assoc;

		for ($i=0; $i<count($index_keys); $i++) {
		
				$key_name = $index_keys[$i];
				if (!isset($row[$key_name])) {
						print "Error: Key $key_name is not present in the results output.\n";
						return(false);
				}

				$key_val= isset($row[$key_name]) ? $row[$key_name]  : "";
		
				if (!isset($pointer[$key_val])) {               

						$pointer[$key_val] = "";
						$pointer = & $pointer[$key_val];
				}
				else {
						$pointer = & $pointer[$key_val];
				}

		}


		foreach ($row as $key => $val) {
					$pointer[$key] = $val;
		}

		$result->close();

		return($assoc);               
		}
	}

}
?>